package com.ynet.middleground.approve.listener.user;

import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.activiti.engine.runtime.ProcessInstance;
import org.springframework.context.annotation.DependsOn;

import com.ynet.middleground.approve.cmd.SpringContextUtils;
import com.ynet.middleground.approve.listener.BaseListener;
import com.ynet.middleground.approve.model.UserCenterModel;

/**
 * @author liulx
 * @description 添加黑名单监听
 * @date 2019-12-05 23:18
 */
@DependsOn("springContextUtils")
public class AddBlacklistListener extends BaseListener implements ExecutionListener {

    private UserCenterModel userCenterModel = SpringContextUtils.getBean(UserCenterModel.class);

    private static String addBlacklistReasonKey = "blacklistReason";

    @Override
    public void notify(DelegateExecution delegateExecution) {
        ProcessInstance processInstance =
            processRuntimeModel.getProcessInstance(delegateExecution.getProcessInstanceId());
        String startUserId = processInstance.getStartUserId();
        String channel = getChannel(delegateExecution);
        String operationUserId = getOperationUserId(delegateExecution);
        String reason = getVariableInstance(delegateExecution, addBlacklistReasonKey);
        userCenterModel.addBlacklist(startUserId, channel, Integer.valueOf(operationUserId), reason);
    }
}
